{include file="public/header" /}
<body class="gray-bg">
<div class="wrapper wrapper-content">
    <div class="ibox float-e-margins">
        <div class="ibox-content">
            <div class="row">
                <!--搜索框开始-->
                <div class="col-sm-12">
                    <div class="layui-form layui-form-item">
                        <div class="layui-input-inline layui-form">
                            <select name="fapiao_type" lay-search="" class="layui-input">
                                <option value="">全部类型</option>
                                <option value="1">个人</option>
                                <option value="2">企业</option>
                            </select>
                        </div>
                        <div class="layui-input-inline layui-form">
                            <select name="contract" lay-search="" class="layui-input">
                                <option value="">不限订单类型</option>
                                <option value="1">自营订单</option>
                                <option value="2">增补订单</option>
                            </select>
                        </div>
                        <div class="layui-input-inline layui-form">
                            <select name="fapiao_status" lay-search="" class="layui-input">
                                <option value="">开票状态</option>
                                <option value="2">待开票</option>
                                <option value="3">开票中</option>
                                <option value="4">开票成功</option>
                                <option value="5">开票失败</option>
                            </select>
                        </div>
                        <div class="layui-input-inline layui-form">
                            <input type="text" class="layui-input search" name="n_title" placeholder="手机号/学校名字/订单号"/>
                        </div>
                        <div class="layui-input-inline layui-form">
                            <input type="text"  name="start" onfocus="wk.lay_date(this);"  class="layui-input layer-date search" placeholder="申请开始时间" />
                        </div>
                        <div class="layui-input-inline layui-form">
                            <input type="text"  name="end" onfocus="wk.lay_date(this);"  class="layui-input layer-date search" placeholder="申请结束时间" />
                        </div>

                        <div style="clear: both;height: 10px;"></div>
                        <div class="layui-input-inline" style="margin-left: 10px;">
                            <button class="layui-btn" lay-submit="" lay-filter="LAY-search">立即搜索</button>
                            <button class="layui-btn layui-btn-normal" id="empty" lay-submit="" lay-filter="LAY-search">
                                重置
                            </button>
                        </div>
                    </div>
                </div>
                <!--搜索框结束-->
                <!--操作框开始-->
<!--                <div class="col-sm-12">-->
<!--                    <div class="input-group" >-->
<!--                        <button  class="btn btn-danger m-l-xs" href="javascript:;" data-toggle="dropdown">-->
<!--                            <i class="fa fa-wrench"></i> 导出 <span class="caret"></span>-->
<!--                        </button>-->
<!--                        <ul class="dropdown-menu layui-anim layui-anim-upbit" role="menu">-->
<!--                            <li><a  href="javascript:;" class="layuiBtn" data-type="excelAll"><i class="fa fa-print"></i> 导出汇总</a></li>-->
<!--                            <li><a  href="javascript:;" class="layuiBtn" data-type="excelAllDetail"><i class="fa fa-print"></i> 导出明细</a></li>-->
<!--                        </ul>-->
<!--                    </div>-->
<!--                </div>-->
                <!--操作框结束-->
            </div>

            <div class="hr-line-dashed"></div>

            <div class="example-wrap">
                <div class="example">
                    <table class="layui-hide" id="test" lay-filter="testReload"></table>

                    <!--状态显示模板-->
                    <script type="text/html" id="fapiao_type">
                        {{# if(d.fapiao_type == 1){ }}
                        个人
                        {{# } }}
                        {{# if(d.fapiao_type == 2){ }}
                        企事业单位
                        {{# } }}
                    </script>
                    <!--状态显示模板-->
                    <script type="text/html" id="order_contract">
                        {{# if(d.order_contract == 1){ }}
                        自营订单
                        {{# } }}
                        {{# if(d.order_contract == 2){ }}
                        增补订单
                        {{# } }}
                    </script>
                    <script type="text/html" id="fapiao_status">
                        {{# if(d.fapiao_status == 2){ }}
                        待开票
                        {{# } }}
                        {{# if(d.fapiao_status == 3){ }}
                        开票中(查询可更新)
                        {{# } }}
                        {{# if(d.fapiao_status == 4){ }}
                        <span style="color: limegreen;">开票成功</span>
                        {{# } }}
                        {{# if(d.fapiao_status == 5){ }}
                        <span style="color: orangered;">开票失败</span>
                        {{# } }}
                        {{# if(d.fapiao_status == 6){ }}
                        <span style="color: gray;">无需开票</span>
                        {{# } }}
                    </script>
                    <script type="text/html" id="fapiao_image">
                        {{# if(d.fapiao_image){ }}
                        <a href="https://{{d.fapiao_image}}" target="_blank" style="color:cornflowerblue;">点击查看</a>
                        {{# }else{ }}
                        -
                        {{# } }}
                    </script>
                    <!--操作模板-->
                    <script type="text/html" id="opeBar">
                        <!-- -->
                        <!--<a href="javascript:;" onclick="wk.href('{:url('orderInfo')}?order_id={{d.order_id}}')" class="btn btn-primary btn-xs m-r-xs" title="详情"><i class="fa fa-info">详情</i></a>-->
                        <a href="javascript:;" onclick="wk.confirm('{{d.order_id}}','{:url('fapiaoInfo')}','确定查询发票吗？')" class="btn btn-primary btn-xs m-r-xs" title="查询发票">查询发票</a>
                        {{# if(d.fapiao_status == 2){ }}
                        <a href="javascript:;" onclick="wk.layer_show('修改', '{:url('editFp')}?order_id={{d.order_id}}')" class="btn btn-primary btn-xs m-r-xs" title="修改">修改</a>
                        <a href="javascript:;" onclick="wk.confirm('{{d.order_id}}','{:url('kaipiao')}','确定要开票吗？')" class="btn btn-warning btn-xs m-r-xs" title="开票">开票</a>
                        {{# } }}
                        {{# if(d.fapiao_status == 5){ }}
                        <a href="javascript:;" onclick="wk.layer_show('修改', '{:url('editFp')}?order_id={{d.order_id}}')" class="btn btn-primary btn-xs m-r-xs" title="修改">修改</a>
                        <a href="javascript:;" onclick="wk.confirm('{{d.order_id}}','{:url('kaipiao')}','确定要重新开票吗？')" class="btn btn-warning btn-xs m-r-xs" title="重新开票">重新开票</a>
                        {{# } }}
                        {{# if(d.fapiao_status == 2 || d.fapiao_status == 5){ }}
                        <a href="javascript:;" onclick="wk.confirm('{{d.order_id}}','{:url('nokaipiao')}','确定无需再开票了吗？')" class="btn btn-warning btn-xs m-r-xs" title="无需开票">无需开票(谨慎操作)</a>
                        {{# } }}
                    </script>
                </div>
            </div>
        </div>
    </div>
</div>
<textarea id="allidsForOut" class="hidden"></textarea>
{include file="public/footer" /}
<script>
    //layui渲染数据表格
    layui.use('table', function () {
        var table = layui.table
            , form = layui.form;
        table.render({
            elem: '#test'
            , url: '{:url("Fapiao/index")}'
            , response: {
                statusCode: 220 //成功的状态码，默认：0
            }
            , page: true
//            , size: 'lg' //sm小尺寸的表格 lg大尺寸
            , cellMinWidth: 150
            , limits: [5, 10, 15, 20, 25, 30]
            , limit: "{:config('pages')}"
            , loading: true
            , id: 'testReload'
            , cols: [[
                {type: 'checkbox', fixed: 'left',}
                , {type: 'numbers', width: 80, title: '序号'}
                , {field: 'fapiao_type', width: '', title: '发票类型', align: 'center', toolbar: '#fapiao_type'}
                , {field: 'order_contract', width: '', title: '订单类型', align: 'center', toolbar: '#order_contract'}
                , {field: 'fapiao_head', width: '', title: '抬头', align: 'center'}
                , {field: 'fapiao_shui', width: '', title: '税号', align: 'center'}
                , {field: 'user_phone', width: '', title: '手机号', align: 'center'}
                , {field: 'fapiao_email', width: '', title: '邮箱', align: 'center'}
                , {field: 'total_price', width: '', title: '总金额', align: 'center'}
                , {field: 'user_username', width: '', title: '申请用户', align: 'center'}
                , {field: 'order_no', width: '', title: '所属订单', align: 'center'}
                , {field: 'fapiao_time', width: '', title: '申请时间', align: 'center'}
                , {field: 'deleted_at', width: '', title: '处理时间', align: 'center'}
                , {field: 'fapiao_image', width: '', title: '发票', align: 'center', toolbar: '#fapiao_image'}
                , {field: 'school_name', width: '', title: '学校名称', align: 'center'}
                , {field: 'fapiao_remark', width: '', title: '备注', align: 'center'}
                , {field: 'fapiao_status', width: '', title: '状态', align: 'center', toolbar: '#fapiao_status'}
                , {fixed: 'right', width: 250, title: '操作', align: 'center', toolbar: '#opeBar'}
            ]]
            , done: function (res, curr, count) {
                $('.img-circle').viewer({
                    url: 'data-original',
                });
            }
        });
        //监听状态开关操作
        form.on('switch(OnOff)', function (obj) {
            var num = '';
            obj.elem.checked == true? num = 1: num = 2;
            //用户状态
            wk.status(this.value,num, '{:url("changeGoodStatus")}',obj);
        });
        //批量操作
        var $ = layui.$, active = {
            excelAll: function(){
                //导出Excel
                var schoolid = $('.xm-select-label span').attr('value');
                wk.excelAll('',$('.layui-input').serialize() + '&schoolid='+schoolid,"{:url('excelOutOrder')}");
            },
            excelAllDetail: function(){
                //导出Excel
                var schoolid = $('.xm-select-label span').attr('value');
                wk.excelAll('',$('.layui-input').serialize() + '&schoolid='+schoolid,"{:url('excelOutDetail')}");
            }
        };
        $('.layuiBtn').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
        var getIds = function () {
            var ids = [];
            var checkStatus = table.checkStatus('testReload')
                , data = checkStatus.data;
            $.each(data, function (index, item) {
                ids.push(item['n_id'])
            });
            return ids;
        }
    });
</script>
</body>
</html>